${r"<#import '/ftlLibrary/properteisVariable.ftl' as pv/>"}
<div class="row">
	<div class="col-lg-12 col-sm-12 col-xs-12">
		<div class="widget">
			<div class="widget-header bordered-bottom theme">
				<span class="widget-caption">${baseInfo.businessDescription}-${r"${(editModel=='add')?string('新增','编辑')}"}</span>
				<div class="widget-buttons">
					<a href="#" data-toggle="collapse">
						<i class="fa fa-minus"></i>
					</a>
					<a href="#" data-toggle="maximize">
						<i class="fa fa-expand"></i>
					</a>
				</div>
			</div>
			<div class="widget-body">
				<div class="row">
					<form class="editForm" action="${r"${saveUrl}"}" method="post" responseType="JSON" role="form" id="editForm_${r"${serializeNum}"}"
						data-bv-submitButtons="#editFormSubmitBtn_${r"${serializeNum}"}"
						data-bv-message="This value is not valid"
						data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
						data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
						data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">
							<#list table.columns as column>
							<#if  !column.ucf??>
							<#-- 主键-->
							<#if column.isPrimaryKey>
							<input type="hidden" name="${column.columnJavaFieldName}" value="${r"${editEntity."+column.columnJavaFieldName+"}"}">
							<#--是否存在数据源-->
							<#elseif column.datasourceSql??&&column.datasourceKeyColumn??&&column.datasourceValueColumn??>
							<#--可编辑性控制-->
							${r"<#if ("+column.isAddCanEdit?c+" && editModel=='add')||("+column.isUpdateCanEdit?c+" && editModel=='edit')>"}
							<div class="col-xm-12 col-sm-6 col-lg-4">
								<div class="form-group">
									<label for="${column.columnJavaFieldName}" class="col-sm-2 control-label no-padding-right">${column.datasourceName}</label>
									<div class="col-sm-10">
										<#assign selectName='${column.columnJavaFieldName}' />
										<select name="${selectName}" class="selectpicker_${r"${serializeNum}"}" data-live-search="true">
										<optgroup label="选择所属分组" data-icon="icon-ok">
											<option value="">无</option>
											${r"<#list "+ column.columnJavaFieldName+"_datasources" +" as datasources >"}
											<option value="${r"${datasources."+column.datasourceKeyColumn+"}"}">${r"${datasources."+column.datasourceValueColumn+"}"}</option>
											${r"</#list>"}
										</optgroup>
										</select>
										<script type="text/javascript">
											$("[name='${selectName}']").val("${r"${editEntity."+column.columnJavaFieldName+"}"}");
										</script>
									</div>
								</div>
							</div>
							${r"</#if>"}
							<#--单选类型-->
							<#elseif column.columnJavaType=="java.lang.Boolean"||column.columnJavaType=="boolean">
							${r"<#if ("+column.isAddCanEdit?c+" && editModel=='add')||("+column.isUpdateCanEdit?c+" && editModel=='edit')>"}
							<div class="col-xm-12 col-sm-6 col-lg-4">
								<div class="form-group has-feedback">
									<label for="${column.columnJavaFieldName}" class="col-sm-2 control-label no-padding-right">${column.remarks}</label>
									<div class="col-sm-10">
										<input type="hidden" name="${column.columnJavaFieldName}" value=${r"${(editEntity."+column.columnJavaFieldName+"???string(editEntity."+column.columnJavaFieldName+"?string('true','false'),'false'))!'false'}"}>
										<label>
											<input ${column.attrStr} ${r"${(editEntity."+column.columnJavaFieldName+"???string(editEntity."+column.columnJavaFieldName+"?string('checked',''),''))!''}"}>
											<span class="text"></span>
										</label>
									</div>
								</div>
							</div>
							${r"</#if>"}
							<#--时间类型-->
							<#elseif column.columnJavaType=="java.util.Date"||column.columnJavaType=="java.sql.Timestamp">
							${r"<#if ("+column.isAddCanEdit?c+" && editModel=='add')||("+column.isUpdateCanEdit?c+" && editModel=='edit')>"}
							<div class="col-xm-12 col-sm-6 col-lg-4">
								<div class="form-group">
									<label for="${column.columnJavaFieldName}" class="col-sm-2 control-label no-padding-right">${column.remarks}</label>
									<div class="col-sm-10">
										<span class="input-icon icon-left">
											<input ${column.attrStr} value="${r"${editEntity."+column.columnJavaFieldName+"}"}"/>
											<i class="fa fa-calendar"></i>
										</span>
									</div>
								</div>
							</div>
							${r"</#if>"}
							<#else>
							${r"<#if ("+column.isAddCanEdit?c+" && editModel=='add')||("+column.isUpdateCanEdit?c+" && editModel=='edit')>"}
							<div class="col-xm-12 col-sm-6 col-lg-4">
								<div class="form-group">
									<label for="${column.columnJavaFieldName}" class="col-sm-2 control-label no-padding-right">${column.remarks}</label>
									<div class="col-sm-10">
										<input ${column.attrStr} value="${r"${editEntity."+column.columnJavaFieldName+"}"}" />
										<span class="text"></span>
									</div>
								</div>
							</div>
							${r"</#if>"}
							</#if>
							</#if>
							</#list>
							<#list table.columns as column>
							<#--文件上传-->
							<#if column.ucf??>
							${r"<#if ("+column.isAddCanEdit?c+" && editModel=='add')||("+column.isUpdateCanEdit?c+" && editModel=='edit')>"}
							<div class="col-xm-12 col-sm-6 col-lg-4">
								<input type="hidden" name="${column.columnJavaFieldName}" value="${r"${editEntity."+column.columnJavaFieldName+"}"}">
								<input type="hidden" name="delete${column.columnJavaGetterOrSetterSuffix}">
								<div class="form-group">
									<label for="${column.columnJavaFieldName}" class="col-sm-2 control-label no-padding-right">${column.remarks}</label>
									<div class="col-sm-10">
										<div class="col-xs-9">
											<input data-bv-message="The field is not valid" maxlength="100" name="new${column.columnJavaGetterOrSetterSuffix}" id="${column.columnJavaFieldName}${r"${serializeNum}"}" readonly="readonly" alt="${column.remarks}" id="headPortrait" placeholder="${column.remarks}" type="text" title="头像" class="form-control"/>
											<span class="text"></span>
										</div>
										<div class="col-sm-2">
											<a href="javascript:void(0);" class="btn theme" onclick="upload${column.columnJavaGetterOrSetterSuffix}('editForm_${r"${serializeNum}"}','new${column.columnJavaGetterOrSetterSuffix}','${column.columnJavaFieldName}','${column.columnJavaFieldName}_imgPrev${r"${serializeNum}"}','${column.ucf.groupName}')"><i class="fa fa-upload"></i>上传</a>
										</div>
										<div class="col-sm-12 imgPrev" id="${column.columnJavaFieldName}_imgPrev${r"${serializeNum}"}">
											${r"<@file fileIds=editEntity."+column.columnJavaFieldName+" separator=','  ;files>"}
												${r"<#list files as file>"}
													<p>
														<#if column.ucf.uploadType == "Image">
														<img src="${r"${pv.fileRedPath}/${file.relativePath}/${file.fileName}"}" width="50" height="50">
														<#elseif column.ucf.uploadType=="Excel">
														<img src="assets/img/excelBg.jpg" width="50" height="50">
														<#elseif column.ucf.uploadType=="World">
														<img src="assets/img/worldBg.png" width="50" height="50">
														</#if>
														${r"${file.fileName}<#if file.size??>&nbsp;&nbsp;尺寸:${file.size}</#if>"}
														<a class="btn btn-default btn-xs icon-only red delete textAling-right" href="javascript:void(0);" onclick="removeFileUseLog(this,'editForm_${r"${serializeNum}"}','delete${column.columnJavaGetterOrSetterSuffix}','${column.columnJavaFieldName}','${r"${file.id}"}')"><i class="fa fa-trash-o"></i></a>
													</p>
												${r"</#list>"}
											${r"</@file>"}
										</div>
									</div>
								</div>
							</div>
                            <script type="text/javascript">
							    function upload${column.columnJavaGetterOrSetterSuffix}(formId, targetShowInputName, targetHideInputName, imgPrevId, groupName) {
							        showUploadFileDialog({
							            groupName: groupName,
							        	size:"${column.ucf.size}",//文件上传组件层大小，small 小,large 大 
							        	title:"${column.ucf.title}",//文件上传组件层标题
							        	width:"${column.ucf.width}",//文件上传组件层宽度
							        	height:"${column.ucf.height}",//文件上传组件层高度
							            fileNumLimit: ${column.ucf.fileNumLimit},//验证文件总数量, 超出则不允许加入队列
							        	fileSizeLimit:"${column.ucf.fileSizeLimit}",// 验证文件总大小是否超出限制, 超出则不允许加入队列 
							        	fileSingleSizeLimit:"${column.ucf.fileSingleSizeLimit}",//该参数将参与文件缓存时的唯一标识值,如果配置了文件服务器,该参数同时会参与文件服务器文件存储目录分配,为保证文件不丢失, 务必保证同一编辑页面此参数唯一
							        	<#if column.ucf.uploadType != "All">
							        	accept:{
							        		title:"${column.ucf.accept_title}",//文字描述
							        		extensions:"${column.ucf.accept_extensions}",//允许的文件后缀，不带点，多个用逗号分割
							        		mimeTypes:"${column.ucf.accept_mimeTypes}"// 多个用逗号分割
							        	},
							            </#if>
							        	<#if column.ucf.uploadType == "Image">
							        	imgMaxWidth:"${column.ucf.imgMaxWidth}",//图片文件允许的最大宽度
							        	imgMaxHeight:"${column.ucf.imgMaxHeight}",// 图片文件允许的最大高度
							            sizes: '${column.ucf.sizes}',//缩放尺寸(格式：宽度-高度,宽度-高度,宽度-高度....),如：500-300,400-300
							            </#if>
							        }, function (result) {//点击确认的回调函数
							            if (result) {
							                console.log(result.fileList);
							                var showWidth = 50, showHeight = 50;
							                var fileList = result.fileList;
							                <#if column.ucf.fileNumLimit=="1">
							                 $("#" + imgPrevId+" p a").click();
							                <#else>
							                 $("#" + imgPrevId).append("<hr>");
						                 	</#if>
							                for (var i = 0, len = fileList.length; i < len; i++) {
							                    var file = fileList[i];
							                    var width = file.size.width;
							                    var height = file.size.height;
						                        var uuid = file.uuid;
						                    	var targetInput = $("#" + formId + " [name='" + targetShowInputName + "']").val(groupName + "=>" + targetHideInputName);
						        				<#if column.ucf.uploadType=="Image">
							                    if (width == -1 && height == -1) {
							                        $("#" + imgPrevId).append('<p><img src="fileUpload/previewUploadImg.do?groupName=' + groupName + '&fileId=' + uuid + '" width="' + showWidth + '" height="' + showHeight + '">'+file.name+'<a class="btn btn-default btn-xs icon-only red delete" href="javascript:void(0);" onclick="remove${column.columnJavaGetterOrSetterSuffix}UploadTempleFile(this,'+"'"+groupName+"','"+uuid+"'"+')"><i class="fa fa-trash-o"></i></a></p>');
							                    }
						                        <#elseif column.ucf.uploadType=="Excel">
						                        $("#" + imgPrevId).append('<p><img src="assets/img/excelBg.jpg" width="' + showWidth + '" height="' + showHeight + '">'+file.name+'<a class="btn btn-default btn-xs icon-only red delete" href="javascript:void(0);" onclick="remove${column.columnJavaGetterOrSetterSuffix}UploadTempleFile(this,'+"'"+groupName+"','"+uuid+"'"+')"><i class="fa fa-trash-o"></i></a></p>');
						                        <#elseif column.ucf.uploadType=="World">
						                        $("#" + imgPrevId).append('<p><img src="assets/img/worldBg.png" width="' + showWidth + '" height="' + showHeight + '">'+file.name+'<a class="btn btn-default btn-xs icon-only red delete" href="javascript:void(0);" onclick="remove${column.columnJavaGetterOrSetterSuffix}UploadTempleFile(this,'+"'"+groupName+"','"+uuid+"'"+')"><i class="fa fa-trash-o"></i></a></p>');
						                        <#else>
						                        $("#" + imgPrevId).append("<p>"+file.name+'<a class="btn btn-default btn-xs icon-only red delete" href="javascript:void(0);" onclick="remove${column.columnJavaGetterOrSetterSuffix}UploadTempleFile(this,'+"'"+groupName+"','"+uuid+"'"+')"><i class="fa fa-trash-o"></i></a></p>');
						                        </#if>
							                }
							            }
							        }, function () {//点击取消的回调函数
							            console.log("执行关闭/取消的回调函数");
							        })
							    }
							    //移除临时文件
						    	function remove${column.columnJavaGetterOrSetterSuffix}UploadTempleFile(that,groupName,uuid){
							    	console.log("clear temp file  by  id...")
							        ajaxRequest("fileUpload/clearTempFile.do", {groupName: groupName,fileId:uuid}, function (result) {
							            if (result.resCode == "200") {
						                    console.log("成功清除缓存文件："+uuid);
						                    $(that).parents("p").remove();
							            } else {
							                var message = result.resMsg;
							                bootbox.alert({
							                    title: "错误提示",
							                    size: 'small',
							                    message: message
							                });
							            }
							        },
							        function (XMLHttpRequest, textStatus, errorThrown) {
							            ajaxError(errorThrown);
							        }, "GET", "JSON")
							    }
                            </script>
							${r"</#if>"}
							</#if>
						</#list>
						<div class="col-sm-12">
							<input type="button" class="btn btn-default" data-dismiss="modal" value="返回" />
							<button type="submit" class="btn btn-blue" id="editFormSubmitBtn_${r"${serializeNum}"}">保存</button>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="assets/js/validation/bootstrapValidator_init.js"></script>
<script>
$(".selectpicker_${r"${serializeNum}"}").select2();
<#list table.columns as column>
<#--文件上传-->
<#if column.ucf??>
function removeFileUseLog(that,formId,targetDeleteInputName,targetHideInputName,fileId){
	var useFileIds=$("#" + formId + " [name='" + targetHideInputName + "']");
	var targetDeleteInput=$("#" + formId + " [name='" + targetDeleteInputName + "']");
	var ids=useFileIds.val().split(",");
	var newIds="";
	for(var i=0,len=ids.length;i<len;i++){
		if(ids[i]==fileId){
			targetDeleteInput.val(targetDeleteInput.val()+","+fileId);
			continue;
		}
		newIds+=ids[i];
		if(i!=len-1){
			newIds+=",";
		}
	}
	useFileIds.val(newIds);
	$(that).parents("p").remove();
}
<#break/>
</#if>
</#list>
</script>